const Sequelize = require('sequelize');
var sequelize = new Sequelize('test', 'root', 'mysql', {
  host: 'localhost',
  dialect: 'mysql',
});

var Test1 = sequelize.define('test1', {
  id: {
    primaryKey: true,
    type: Sequelize.INTEGER
  },
  name: {
    type: Sequelize.STRING,
    field: 'name' // Will result in an attribute that is firstName when user facing but first_name in the database
  },

}, {
  tableName: 'test1',
  timestamps: false
});


var Test2 = sequelize.define('test2', {
  id: {
    primaryKey: true,
    type: Sequelize.INTEGER
  },
  name: {
    type: Sequelize.STRING,
    field: 'name' // Will result in an attribute that is firstName when user facing but first_name in the database
  },
  Test1Id: {
    type: Sequelize.INTEGER,
    field: 'test1id'
  }
}, {
  tableName: 'test2',
  timestamps: false
});
async function app() {
  Test1.hasMany(Test2, {foreignKey: 'Test1Id', targetKey: 'id'})
  const res = await Test1.findAll({
    include: [{
      model: Test2,
      // where: { id: Sequelize.col('Test2.Test1Id') }
    }]
  });
  console.log(JSON.stringify(res));
}
app();